import random

setAudioAttributes(samplingrate=44100, controlrate=8820)
setChannels(1)
setGlobalDuration(-1)

env = genAdsr()

a = genWaveform([1,0])
b = genWaveform([1,.4,.25])
c = genWaveform([1,.4,.25,.17,.1])
d = genWaveform([1,.4,.25,.17,.1, .07,.05])
e = genWaveform([1,.4,.25,.17,.1, .07,.05,.03,.02])
f = genWaveform([1,.4,.25,.17,.1, .07,.05,.03,.02,.01,.01])
g = genWaveform([1,.4,.25,.17,.1, .07,.05,.03,.02,.01,.01,.012,.015])
h = genWaveform([1,.4,.25,.17,.1, .07,.05,.03,.02,.01,.01,.012,.015,.016,.017])
i = genWaveform([1,.4,.25,.17,.1, .07,.05,.03,.02,.01,.01,.012,.015,.016,.017,.018])
j = genWaveform([1,.4,.25,.17,.1, .07,.05,.03,.02,.01,.01,.012,.015,.016,.017,.018,.019,.02])

waves = [a,b,c,d,e,f,g,h,i,j]

beginMidiSynth(release=2, skipampscaling=True)

randomi(bus=[1,2,3,4], mini=.995, maxi=1.005, rate=[2.04,3.1,4.01,2.67])

for k in range(10):
    splitVelocity(minthresh=k*.1, maxthresh=k*.1+.1)
    pitchs = [random.randint(1980,2020)*0.1 for i in range(8)]
    waveform(pitch=pitchs, amplitude=.1, envelope=env, pitchVar=[1,2,3,4], table=waves[k])

endMidiSynth(out='synth')

waveguideReverb(input='synth', amplitude=.5)

startCsound()